package com.kclm.xsap.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kclm.xsap.dao.EmployeeDao;
import com.kclm.xsap.dao.GlobalSetDao;
import com.kclm.xsap.entity.EmployeeEntity;
import com.kclm.xsap.entity.GlobalReservationSetEntity;
import com.kclm.xsap.service.EmployeeService;
import com.kclm.xsap.service.GlobalSetService;
import com.kclm.xsap.utils.exception.RRException;
import com.kclm.xsap.utils.exception.ServiceException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class GlobalSetServiceImpl extends ServiceImpl<GlobalSetDao, GlobalReservationSetEntity> implements GlobalSetService {
@Autowired
GlobalSetDao globalSetDao;
//    GlobalReservationSetEntity(id=1, startDay=1, endHour=2, endDay=1, endTime=17:30, cancelHour=2,
//    cancelDay=1, cancelTime=12:00, createTime=null, lastModifyTime=null, version=51, appointmentStartMode=1,
//    appointmentDeadlineMode=1, appointmentCancelMode=1)
    @Override
    public boolean isUpdate(GlobalReservationSetEntity globalReservationSetEntity) {
        if (globalReservationSetEntity.getAppointmentStartMode() == 2 && globalReservationSetEntity.getAppointmentDeadlineMode() == 3) {
            if (globalReservationSetEntity.getEndDay() >= globalReservationSetEntity.getStartDay()){
                return false;
            }else {
                try {
                    globalSetDao.updateById(globalReservationSetEntity);
                } catch (Exception e) {
                    throw new ServiceException("更新全局预约设置失败！");
                }
                return true;
            }
        }else {
            try {
                globalSetDao.updateById(globalReservationSetEntity);
            } catch (Exception e) {
                throw new ServiceException("更新全局预约设置失败！");
            }
            return true;
        }
    }
}
